package com.u3k.mid;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.List;

public class bd {
    static String a = bd.class.getSimpleName();
    public String b;
    public String c;
    public String d;
    public String e;
    public String f;
    public String g;
    public String h;
    public String i;
    public String j;
    public String k;
    public long l;

    public static void a(Context context, long j) {
        synchronized (bd.class) {
            try {
                LogUtils.LogError(a, "deleteStatisticsInfos time=" + j);
                SQLiteDatabase a = an.a(context).a();
                if (a == null) {
                    LogUtils.LogError(a, "deleteStatisticsInfos db==null");
                } else {
                    a.delete("statistics_table", "time<?", new String[]{String.valueOf(j)});
                }
            } catch (Exception e) {
                LogUtils.LogError(a, "deleteStatisticsInfos e=" + e.getMessage());
            } catch (Throwable th) {
                Class cls = bd.class;
            }
        }
    }

    public static List<bd> b(Context context, long j) {
        List<bd> arrayList;
        Cursor cursor = null;
        synchronized (bd.class) {
            try {
                LogUtils.LogError(a, "getStoredStatisticsInfos time=" + j);
                arrayList = new ArrayList();
                SQLiteDatabase a = an.a(context).a();
                if (a == null) {
                    LogUtils.LogError(a, "getStoredStatisticsInfos db==null");
                } else {
                    cursor = a.rawQuery("select * from statistics_table where time < " + j, null);
                    if (cursor == null) {
                        if (cursor != null) {
                            cursor.close();
                        }
                    } else if (cursor.moveToFirst()) {
                        cursor.moveToFirst();
                        while (!cursor.isAfterLast()) {
                            bd bdVar = new bd();
                            bdVar.l = cursor.getLong(cursor.getColumnIndex("time"));
                            bdVar.b = cursor.getString(cursor.getColumnIndex("moduleName"));
                            bdVar.c = cursor.getString(cursor.getColumnIndex("moduleVer"));
                            bdVar.d = cursor.getString(cursor.getColumnIndex("midVer"));
                            bdVar.e = cursor.getString(cursor.getColumnIndex("shellVer"));
                            bdVar.f = cursor.getString(cursor.getColumnIndex("appId"));
                            bdVar.g = cursor.getString(cursor.getColumnIndex("channelId"));
                            bdVar.h = cursor.getString(cursor.getColumnIndex("bundleId"));
                            bdVar.i = cursor.getString(cursor.getColumnIndex("userToken"));
                            bdVar.j = cursor.getString(cursor.getColumnIndex("event"));
                            bdVar.k = cursor.getString(cursor.getColumnIndex("data"));
                            arrayList.add(bdVar);
                            cursor.moveToNext();
                        }
                        if (cursor != null) {
                            cursor.close();
                        }
                    } else if (cursor != null) {
                        cursor.close();
                    }
                }
            } catch (Exception e) {
                LogUtils.LogError(a, "getStoredStatisticsInfos e=" + e.getMessage());
                if (cursor != null) {
                    cursor.close();
                }
            } catch (Throwable th) {
                Class cls = bd.class;
            }
        }
        return arrayList;
    }

    public void a(Context context) {
        synchronized (this) {
            SQLiteDatabase a = an.a(context).a();
            if (a == null) {
                LogUtils.LogError(a, "save db==null");
            } else {
                try {
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("moduleName", this.b);
                    contentValues.put("moduleVer", this.c);
                    contentValues.put("midVer", this.d);
                    contentValues.put("shellVer", this.e);
                    contentValues.put("appId", this.f);
                    contentValues.put("channelId", this.g);
                    contentValues.put("bundleId", this.h);
                    contentValues.put("userToken", this.i);
                    contentValues.put("event", this.j);
                    contentValues.put("data", this.k);
                    contentValues.put("time", Long.valueOf(this.l));
                    a.insert("statistics_table", "time", contentValues);
                } catch (Exception e) {
                    LogUtils.LogError(a, "save e=" + e.getMessage());
                }
            }
        }
    }
}
